package org.proddevplm.business.user;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.proddevplm.business.api.IAdapter;
import org.proddevplm.business.user.constants.UserMgmtConstants;
import org.proddevplm.constants.UserConstants;
import org.proddevplm.dao.data.User;
import org.proddevplm.helpers.ManagerUtil;

public class UserAdapter implements IAdapter {

	

	public Object adapt(int command, Map<String, Object> dataObject) {

		Object returnObject = null;

		switch (command) {
		case UserMgmtConstants.ADD_USER_COMMAND:
			List<String> user = new ArrayList<String>();
			
			user.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.SURNAME)));
			user.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.NAME)));
			user.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.USERNAME)));
			user.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.PASSWORD)));
			user.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.CONFIRM_PASSWORD)));
			user.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.EMAIL)));
			user.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.TYPE)));
			user.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.COMPANY)));
			user.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.POSITION)));
			
			/*User user = new User();
			
			user.setSurname(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.SURNAME)));
			user.setName(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.NAME)));			
			user.setUsername(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.USERNAME)));
			user.setPassword(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.PASSWORD)));
			user.setEmail(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.EMAIL)));
			//user.setRole(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.ROLE)));
			user.setCompany(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.COMPANY)));
			user.setPosition(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.POSITION)));
			*/
			returnObject = user;
			break;
		case UserMgmtConstants.DELETE_USER_COMMAND:
		case UserMgmtConstants.GET_USER_COMMAND:
			returnObject = dataObject.get(UserMgmtConstants.USER_ID_FIELD);
			break;

		case UserMgmtConstants.UPDATE_USER_COMMAND:
			Map<String, Object> updateDataObject = new HashMap<String, Object>();
			updateDataObject.put(UserMgmtConstants.USER_DATA_FIELD,
					dataObject.get(UserMgmtConstants.USER_DATA_FIELD));
			updateDataObject.put(UserMgmtConstants.USER_ID_FIELD,
					dataObject.get(UserMgmtConstants.USER_ID_FIELD));
			break;
		case UserMgmtConstants.GET_USERS_COMMAND:
			break;
		case UserMgmtConstants.LOGIN_COMMAND:
			String credentials[] = new String[2];
			credentials[0] = ManagerUtil.getStringFromReq(dataObject.get(UserConstants.USERNAME));
			credentials[1] = ManagerUtil.getStringFromReq(dataObject.get(UserConstants.PASSWORD));
			returnObject = credentials;
			break;
			
		case UserMgmtConstants.ADD_MEMBER_ON_PROJECT:
			Map<String, Object> newMemberMap = new HashMap<String, Object>();
			newMemberMap.put("userId", ManagerUtil.getStringFromReq(dataObject.get("selectUser")));
			newMemberMap.put("roleId", ManagerUtil.getStringFromReq(dataObject.get("selectRole")));
			returnObject = newMemberMap;
			break;
			
		case UserMgmtConstants.REMOVE_MEMBER_FROM_PROJECT:
			Map<String, Object> remMemberMap = new HashMap<String, Object>();
			remMemberMap.put("projectId", ManagerUtil.getStringFromReq(dataObject.get("projectId")));
			remMemberMap.put("userId", ManagerUtil.getStringFromReq(dataObject.get("userId")));
			remMemberMap.put("roleId", ManagerUtil.getStringFromReq(dataObject.get("roleId")));
			returnObject = remMemberMap;
			break;
			
		case UserMgmtConstants.CHANGE_ROLE:
			Map<String, Object> changeRoleMap = new HashMap<String, Object>();
			changeRoleMap.put("projectId", ManagerUtil.getStringFromReq(dataObject.get("selectedProjectId")));
			changeRoleMap.put("userId", ManagerUtil.getStringFromReq(dataObject.get("selectedUserId")));
			changeRoleMap.put("currentRoleId", ManagerUtil.getStringFromReq(dataObject.get("exRole")));
			changeRoleMap.put("newRoleId", ManagerUtil.getStringFromReq(dataObject.get("changeRole")));
			returnObject = changeRoleMap;
			break;
			
		case UserMgmtConstants.ADD_GUEST:
			List<String> guest = new ArrayList<String>();
			
			guest.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.SURNAME)));
			guest.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.NAME)));
			guest.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.USERNAME)));
			guest.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.PASSWORD)));
			guest.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.CONFIRM_PASSWORD)));
			guest.add(ManagerUtil.getStringFromReq(dataObject.get(UserConstants.EMAIL)));
			
			returnObject = guest;
		}
		
		return returnObject;
	}
		
}
